package com.wbc.smartHome.web;



import com.wbc.smartHome.model.Result;
import com.wbc.smartHome.model.User;
import com.wbc.smartHome.service.UserService;
import com.wf.captcha.SpecCaptcha;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping(path = "/userApi/userCtl")
@Api(tags = "用户端接口")
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private RedisTemplate redisTemplate;



    @ApiOperation("获取邮箱验证码")
    @GetMapping(path = "/createYzm")
    public Result createYzm(String account) {
        Result result = userService.createYzm(account);
        return result;
    }
    @ApiOperation("用户登录")
    @PostMapping(path = "/loginUser")
    public Result loginUser(@RequestBody User user) {
        Result result = userService.loginUser(user);
        return result;
    }


    @ApiOperation("上传用户头像")
    /*上传封面图*/
    @PostMapping("/uploadImg")
    public Result uploadImg(@RequestParam("file")CommonsMultipartFile commonsMultipartFile) throws IOException {
        Result result = userService.uploadImg(commonsMultipartFile);
        return  result;
    }

    @ApiOperation("修改用户信息并返回")
    @RequestMapping(path = "/save")
    public Result save(@RequestBody User user,@RequestHeader("userToken") String userToken){
        User user1 = userService.update(user,userToken);
        Result result = null;
        if(user1==null){
            result = new Result(201,"token验证失败",null);
        }
        else {
            result = new Result(200, "保存成功", user1);
        }
        return  result;
    }

}
